<?php

class Vlib_Loader extends Zend_Loader_Autoloader_Resource {
    
     public function __construct($options) {
        parent::__construct($options);
    }
    
    /**-----------------------------------------------------------------------------------
     * @desc Auto load a class
     * 
     * @author Tuyendn <tuyendn@vnext.vn>
     *-----------------------------------------------------------------------------------*/
    public function autoload($class) {
        $prefix = APPLICATION_PATH . DS;
        $paths = @explode('_', $class);
        switch (strtolower($paths[0])) {
            default :
                $prefix .= 'modules' . DS;
                break;
        }
        // get current class name
        $className = $paths[count($paths) - 1];
        $classFile = substr($class, 0, -strlen($className));
        $classFile = $prefix . strtolower(str_replace('_', DS, $classFile)) . $className . '.php';
        if (file_exists($classFile)) {
            require_once $classFile;
        } else {
            throw new Exception($classFile . ' not found');
        }
        return false;
    }
}